import {
	defineStore
} from 'pinia'
import {
	ref
} from 'vue'

export const userStore = defineStore("user", () => {
	
	let token = ref("")
	let userInfo = ref({})
	let isLogin = ref(false)
	
	function addUserInfo(username,password,token){
		this.userInfo.username = username
		this.userInfo.password = password
		this.token = token
		this.isLogin = true
	}
	
	function clearUserInfo(){
		this.userInfo = {}
		this.token = ""
		this.isLogin = false
	}
	
	
	let hasPos = ref(false)
	let currentPos = ref({
		latitude: 34.32750923809711,
		longitude: 108.93537380111717
	})
	function setPos(lat, lon) {
		currentPos.value.latitude = lat
		currentPos.value.longitude = lon
		hasPos.value = true
	}
	return {
		currentPos,
		hasPos,
		setPos,
		token,
		userInfo,
		isLogin,
		addUserInfo,
		clearUserInfo
	}
})